// =====================================================================
//
//  This file is part of the Microsoft Dynamics CRM SDK code samples.
//
//  Copyright (C) Microsoft Corporation.  All rights reserved.
//
//  This source code is intended only as a supplement to Microsoft
//  Development Tools and/or on-line documentation.  See these other
//  materials for detailed information regarding Microsoft code samples.
//
//  THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//
// =====================================================================
using System;
using System.Runtime.Serialization;
using Microsoft.Xrm.Sdk.Temporary;

namespace Microsoft.Crm.Sdk.Messages
{
	/// <summary>
	/// Defines .
	/// </summary>
	[DataContract(Namespace = "http://schemas.microsoft.com/crm/2011/Contracts")]
	public sealed class TimeInfo : IExtensibleDataObject
	{
		/// <summary>
		/// Beginning of the time interval.
		/// </summary>
		[DataMember]
		public DateTime? Start { get; set; }

		/// <summary>
		/// End of the time interval.
		/// </summary>
		[DataMember]
		public DateTime? End { get; set; }

		/// <summary>
		/// High-level classification of the time block.
		/// </summary>
		[DataMember]
		public TimeCode TimeCode { get; set; }

		/// <summary>
		/// More specific classification of the TimeCode.
		/// </summary>	
		[DataMember]
		public SubCode SubCode { get; set; }

		/// <summary>
		/// Unique identifier of the object that generated this instance.
		/// </summary>
		/// <example>
		/// For example, for time block generated by calendar rules, SourceId
		/// is equal to calendar rule is.
		/// </example>
		[DataMember]
		public Guid SourceId { get; set; }

		/// <summary>
		/// Unique identifier of the calendar that generated this instance.
		/// For TimeInfo that is generated from non-Calendar source, it is Guid.Empty.
		/// </summary>
		[DataMember]
		public Guid CalendarId { get; set; }

		/// <summary>
		/// CRM object type code of the object that generated this instance.
		/// </summary>
		[DataMember]
		public int SourceTypeCode { get; set; }

		[DataMember]
		public bool IsActivity { get; set; }

		[DataMember]
		public int ActivityStatusCode { get; set; }

		/// <summary>
		/// Effort required to perform an action.
		/// </summary>
		[DataMember]
		public double Effort { get; set; }

		/// <summary>
		/// Text associated with the time block.
		/// </summary>
		[DataMember]
		public string DisplayText { get; set; }

		#region IExtensibleDataObject Implementation
		private ExtensionDataObject _extensionDataObject;
		public ExtensionDataObject ExtensionData
		{
			get
			{
				return _extensionDataObject;
			}
			set
			{
				_extensionDataObject = value;
			}
		}
		#endregion IExtensibleDataObject Implementation
	}

	/// <summary>
	/// High-level classification of the period of time.
	/// </summary>
	[DataContract(Namespace = "http://schemas.microsoft.com/crm/2011/Contracts")]
	public enum TimeCode
	{
		/// <summary>Time is available.</summary>
		[EnumMember]
		Available,

		/// <summary>Time is completely or partially busy,</summary>
		[EnumMember]
		Busy,

		/// <summary>Time is completely unavailable.</summary>
		[EnumMember]
		Unavailable,

		/// <summary>Block of time represents additional information or restriction.</summary>
		[EnumMember]
		Filter
	}

	/// <summary>
	/// More specific classification of a particular TimeCode value.
	/// </summary>
	[DataContract(Namespace = "http://schemas.microsoft.com/crm/2011/Contracts")]
	public enum SubCode
	{
		/// <summary>No specific reason provided.</summary>
		[EnumMember]
		Unspecified,		// Available, Unavailable

		/// <summary>Time can be scheduled.</summary>
		[EnumMember]
		Schedulable,		// Available

		/// <summary>Time is committed to perform an action.</summary>
		[EnumMember]
		Committed,			// Busy

		/// <summary>Time is tentatively committed to perform an action.</summary>
		[EnumMember]
		Uncommitted,		// Busy

		/// <summary>Time cannot be scheduled because of a hard break.</summary>
		[EnumMember]
		Break,				// Unavailable

		/// <summary>Time cannot be scheduled because of a holiday.</summary>
		[EnumMember]
		Holiday,			// Unavailable

		/// <summary>Time cannot be scheduled because of a vacation.</summary>
		[EnumMember]
		Vacation,			// Unavailable

		/// <summary>Time cannot be scheduled because of a blocking appointment.</summary>
		[EnumMember]
		Appointment,			// Unavailable

		/// <summary>Filter to restrict appointments started for a resource.</summary>
		[EnumMember]
		ResourceStartTime,			// Filter

		/// <summary>Restricts time for a resource for a specific service.</summary>
		[EnumMember]
		ResourceServiceRestriction,	// Filter

		/// <summary>Contain capacity information for a work plan.</summary>
		[EnumMember]
		ResourceCapacity,			    // Filter

		/// <summary>Global service time restriction filter.</summary>
		[EnumMember]
		ServiceRestriction,			// Filter

		/// <summary>Service cost overwrite for effort required per resource.</summary>
		[EnumMember]
		ServiceCost					// Filter
	}
}
